import random
import sys
money = 5000
scar1 = []
scar2 = []
scar = []
cmod1 = ["dk",30]
cmod2 = ['puy',40]
cmod3 = ["bob",50]
cmod4 = ["fk",60]
cmod = [
    ["dk",30],
    ["puy",40],
    ["bob",50],
    ["fk",60]
]
cmodd = ["dk","puy","bob","fk"]

dk = 'dk'
puy = 'puy'
bob = 'bob'
fk = 'fk'
exit = 'exit'
sum = 0
print("--------------欢迎光临度小满商场！--------------")
discont=random.randint(1,10)
i = random.randint(0,3)

cname = cmod[i][0]
print("恭喜你获得一张",cname,discont,"折优惠券")

print("请输入1进入商场，输入其他默认退出购物")
sign = input("请输入")
if sign.isdigit():
    sign=int(sign)
if sign==2 :
    sys.exit()
if sign==1 :
    for key,value in enumerate(cmod):
        print(key+1,value)
    while True:
        buy = input("请输入你选择的商品，输入exit退出购买并打印小票")
        if buy.isdigit():
            buy = int(buy)
            if buy >= len(cmod)+1 or buy == 0:
                print("对不起暂无商品")
            else:
                if money > cmod[buy-1][1]:
                    scar.append(cmod[buy-1])
                    if cmod[buy-1][0] == cname:
                        money = money-(discont/10*cmod[buy-1][1])
                        sum = sum+(discont/10*cmod[buy-1][1])
                        cname=None
                    else:
                        money = money - cmod[buy - 1][1]
                        sum = sum + cmod[buy - 1][1]

                    print("恭喜你购买成功，余额还剩",money,"元")
                else:
                    print("余额不足，重新购买")
        elif buy == "exit":
            print("------商品小票------")
            print("商品名称","商品价格")
            for i in scar:
                print(i)
            print("余额还剩",money,"元")
            print("总共花费",sum,"元")
            print("----欢迎下次光临----")
            sys.exit()
        else:
            print("无法识别请重新输入")


'''
while money > 30:
    
    if buy==dk :
        scar1.append('dk')
        scar2.append(30)
        if discont==1 or discont==2 or discont==3 :
            discont=discont/10
            money=money-(cmod1[-1]*discont)
            sum = sum + (cmod1[-1]*discont)
        else:
            money=money-cmod1[-1]
            sum = sum + cmod1[-1]
        print("恭喜你购买成功，余额还剩", money)
    if buy==puy :
        scar1.append('puy')
        scar2.append(40)
        if discont == 4 or discont == 5 or discont == 6:
            discont = discont / 10
            money=money-(cmod2[-1]*discont)
            sum = sum + (cmod2[-1]*discont)
        else:
            money=money-cmod2[-1]
            sum = sum + cmod2[-1]
        print("恭喜你购买成功，余额还剩", money)
    if buy==bob :
        scar1.append('bob')
        scar2.append(50)
        if discont == 7 or discont == 8 :
            discont = discont / 10
            money = money - (cmod3[-1]*discont)
            sum = sum + (cmod3[-1]*discont)
        else:
            money = money - cmod3[-1]
            sum = sum + cmod3
        print("恭喜你购买成功，余额还剩", money)
    if buy == fk:
        scar1.append('fk')
        scar2.append(60)
        if discont == 9 or discont == 10 :
            discont = discont / 10
            money = money - (cmod4[-1]*discont)
            sum = sum + (cmod4[-1]*discont)
        else:
            money = money - cmod4[-1]
            sum = sum + cmod4[-1]
        print("恭喜你购买成功，余额还剩", money)
    if buy==exit :
        print("商品名称", scar1)
        print("商品价格",scar2)
        print("总共花费", sum,"元")
        print("优惠",discont*10,"折")
        sys.exit()
'''
